package com.demo.user;

import com.demo.common.model.Blog;
import com.demo.common.model.User;
import com.demo.common.util.WebUtil;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.SqlPara;

public class UserService {

    private User dao = new User().dao();

    public User Login(String username,String password){
        password= WebUtil.encrypt(password);
        String sql="select id,hm,role from user where hm='"+username+"' and pwd='"+password+"'";
        return dao.findFirst(sql);
    }

    public Page<User> paginate(int pageNumber, int pageSize) {
        return dao.paginate(pageNumber, pageSize, "select *", "from user order by id asc");
    }

    public Page<User> paginate(int pageNumber, int pageSize, Kv cond) {
        SqlPara sqlPara = dao.getSqlPara("searchUser",cond);
        return dao.paginate(pageNumber, pageSize, sqlPara);
    }

    public User findByHm(String hm){
        String sql="select id,hm,role from user where hm='"+hm+"'";
        return dao.findFirst(sql);
    }

    public User findById(int id) {
        return dao.findById(id);
    }

    public void deleteById(int id) {
        dao.deleteById(id);
    }
}
